package com.sicheng.lc.周赛.分类.dp;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/6/30 23:27
 */
public class 数组的最大与和 {
    //https://leetcode.cn/problems/maximum-and-sum-of-array/
    int[] st;
    boolean[] used;
    int res = -1;

    //https://leetcode.cn/problems/maximum-and-sum-of-array/solution/shi-ji-shang-shi-0-1bei-bao-wen-ti-shi-j-ipgo/
    public int maximumANDSum(int[] nums, int numSlots) {
        return -1;

    }

    private int dfs(int[] nums, int numSlots) {
        st = new int[numSlots + 1];
        used = new boolean[nums.length];
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] <= numSlots && st[nums[i]] < 2) {
                used[i] = true;
                st[nums[i]]++;
            }
        }
        dfs(0, nums, 0);
        return res;
    }

    //
    void dfs(int x, int[] nums, int sum) {
        if (x == nums.length) {
            res = Math.max(res, sum);
            return;
        }
        if (used[x])
            dfs(x + 1, nums, sum);
        else
            for (int i = 1; i < st.length; i++) {
                if (st[i] == 2)
                    continue;
                st[i]++;
                dfs(x + 1, nums, sum + (nums[x] & i));
                st[i]--;
            }
    }

    public static void main(String[] args) {

    }
}
